package com.example.concurrent.demo.atomic;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author susc
 * @title: AtomicReferenceTest
 * @projectName concurrent-demo
 * @description: TODO
 * @date 2021/9/2815:20
 */
public class AtomicReferenceTest {
    public static void main(String[] args) {
        AtomicReference<Person> ar = new AtomicReference<>();
        Person person = new Person("SnailClimb", 22);
        ar.set(person);
        Person updatedPerson = new Person("Dasiy", 20);
        ar.compareAndSet(person, updatedPerson);

        System.out.println(ar.get().getName());
        System.out.println(ar.get().getAge());
    }

}


class Person{
    private String name;

    private int age;

    public Person(String name, int age) {
        super();
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }
}